# Disable in-source builds to prevent source tree corruption.
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
         message(FATAL_ERROR "FATAL: In-source builds are not allowed.
        You should create a separate directory for build files.")
endif()

cmake_minimum_required(VERSION 3.0.0)

if(POLICY CMP0048)
  cmake_policy(SET CMP0048 NEW)
endif()

PROJECT(coap-demo)

SET(CMAKE_BUILD_TYPE Release)

SET(PRO_TOP_PATH "${PROJECT_SOURCE_DIR}")

# 指定 C 和 C++ 编译器
if (AARCH64_HOST)
  set(CMAKE_C_COMPILER aarch64-linux-musl-gcc)
  set(CMAKE_CXX_COMPILER aarch64-linux-musl-gcc)
  add_executable(coap-server coap-server.c)
  target_include_directories(coap-server PUBLIC ./include)
  target_link_libraries(coap-server
                ${PRO_TOP_PATH}/../lib/aarch64/libcoap-2.so.0.1.0
                ${PRO_TOP_PATH}/../lib/aarch64/libcoapExtra-1.so)

  add_executable(coap-client-test coap-client-test.c)
  target_include_directories(coap-client-test PUBLIC ./include)
  target_link_libraries(coap-client-test 
                  ${PRO_TOP_PATH}/../lib/aarch64/libcoap-2.so.0.1.0
                  ${PRO_TOP_PATH}/../lib/aarch64/libcoapExtra-1.so)
endif()

if (ARM_HOST)
  set(CMAKE_C_COMPILER arm-linux-musleabi-gcc)
  set(CMAKE_CXX_COMPILER arm-linux-musleabi-g++)

  add_executable(coap-server coap-server.c)
  target_include_directories(coap-server PUBLIC ./include)
  target_link_libraries(coap-server
                ${PRO_TOP_PATH}/../lib/arm/libcoap-2.so.0.1.0
                ${PRO_TOP_PATH}/../lib/arm/libcoapExtra-1.so)

  add_executable(coap-client-test coap-client-test.c)
  target_include_directories(coap-client-test PUBLIC ./include)
  target_link_libraries(coap-client-test 
                  ${PRO_TOP_PATH}/../lib/arm/libcoap-2.so.0.1.0
                  ${PRO_TOP_PATH}/../lib/arm/libcoapExtra-1.so)
endif()


# 设置链接时使用的库路径（这些路径将被添加到 RPATH 中，如果 INSTALL_RPATH_USE_LINK_PATH 被设置为 TRUE）
#link_directories(/path/to/first/lib /path/to/second/lib)
# 注意：link_directories 在新版本的 CMake 中不推荐使用，因为它不便于管理路径依赖。
# 更好的做法是使用 target_link_libraries 直接指定库的完整路径或名称（如果库在标准路径下）。


